from ..paradag import DAG

class Node(object):
    def __init__(self, node_id, opr, params, should_execute):
        self.node_id = node_id
        self.opr = opr
        self.params = params
        self.should_execute = should_execute

    def to_dict(self):
        """将 Node 转换为 JSON 兼容的字典"""
        return {
            "node_id": self.node_id,
            "opr": self.opr,
            "params": self.params,
            "should_execute": self.should_execute
        }

class Edge(object):
    def __init__(self, src, dst):
        self.src = src
        self.dst = dst

class Graph(object):
    def __init__(self, nodes_map: map, edges: list):
        self.graph = DAG()
        self.nodes_map = nodes_map
        self.edges = edges
        for key in self.nodes_map.keys():
            self.graph.add_vertex(nodes_map[key])
        for edge in self.edges:
            self.graph.add_edge(nodes_map[edge.src], nodes_map[edge.dst])

    def validateGraph(self):
        """
        Validate the graph if all nodes can be executed in the given order
        """
        print('测试验证DAG', self.graph)
        for n in self.graph.all_starts():
            if n.opr != "img_src":
                return False
        return True

